package com.example.servlet.type;

import com.alibaba.fastjson.JSON;
import com.example.model.Type;
import com.example.service.TypeService;
import com.example.service.impl.TypeServiceImpl;
import com.example.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 获取所有的虚拟商品的类型
 */
@WebServlet("/CollectionServlet/queryAllType")
public class QueryAllTypeServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/json;charset=utf-8");
        TypeService typeService = new TypeServiceImpl();
        List<Type> list = typeService.getAll();
        ResponseData data = ResponseData.ok(list);
        resp.getWriter().println(JSON.toJSONString(data));
    }
}
